package business;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

@SuppressWarnings("serial")
public class OwlGAJAPItestServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String thisUrl = request.getRequestURI();
		response.setContentType("text/html");
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();

		UserService userService = UserServiceFactory.getUserService();
		if (request.getUserPrincipal() == null) {
			out.println("<a href=\"" + userService.createLoginURL(thisUrl) + "\">ログインはこちら</a>");
		} else {
			User user = userService.getCurrentUser();

			out.println("<a href=\"" + userService.createLogoutURL(thisUrl) + "\">ログアウトはこちら</a><br />");
			out.println("name = " + request.getUserPrincipal().getName() + "<br />");
			out.println("isAdmin = " + userService.isUserAdmin() + "<br />");
			out.println("dmain = " + user.getAuthDomain());
			out.println("email = " + user.getEmail());
			out.println("nickname = " + user.getNickname());
		}
	}
}
